package com.nuorui.module.system.controller;

import com.nuorui.common.constant.AdminSwaggerTagConst;
import com.nuorui.common.core.domain.ResponseDTO;
import com.nuorui.module.system.domain.form.DepartmentForm;
import com.nuorui.module.system.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;


/**
 * 部门管理
 *
 * @author: Fred
 * @email 453086@qq.com
 * @create: 2021-10-22 10:42
 */
@RestController
@RequiredArgsConstructor
@Api(tags = AdminSwaggerTagConst.System.SYSTEM_DEPARTMENT)
public class DepartmentController {

    private final DepartmentService departmentService;

    @GetMapping("/departments")
    @ApiOperation(value = "列表查询", notes = "列表查询")
    public ResponseDTO getDepartmentList() {
        return departmentService.getDepartmentList();
    }

    @GetMapping("/departments/tree")
    @ApiOperation(value = "树形列表", notes = "树形列表")
    public ResponseDTO getDepartmentTree() {
        return departmentService.getDepartmentTree();
    }

    @PostMapping("/departments")
    @ApiOperation(value = "新增部门", notes = "新增部门")
    public ResponseDTO saveDepartment(@Valid @RequestBody DepartmentForm departmentForm) {
        return departmentService.saveDepartment(departmentForm);
    }

    @PutMapping("/departments/{departmentId}")
    @ApiOperation(value = "更新部门", notes = "更新部门")
    public ResponseDTO<String> updateDepartment(@PathVariable Long departmentId, @Valid @RequestBody DepartmentForm departmentForm) {
        return departmentService.updateDepartment(departmentId,departmentForm);
    }

    @DeleteMapping("/departments/{departmentId}")
    @ApiOperation(value = "删除部门", notes = "删除部门")
    public ResponseDTO<String> deleteDepartment(@PathVariable Long departmentId) {
        return departmentService.deleteDepartment(departmentId);
    }
}
